package com.hxkcloud.patient.activitys;

import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Message;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import com.hxkcloud.patient.R;
import com.hxkcloud.patient.YjhApplication;
import com.hxkcloud.patient.adapter.NewBetterPlanAdapter;
import com.hxkcloud.patient.adapter.NewDolistAdapter;
import com.hxkcloud.patient.beans.BetterPlanEditBean;
import com.hxkcloud.patient.beans.BetterPlanEditDetailBean;
import com.hxkcloud.patient.beans.DolistEditFuncBean;
import com.hxkcloud.patient.beans.MonitorKindBean;
import com.hxkcloud.patient.dborm.MonitorKindDao;
import com.hxkcloud.patient.popup.CalendarMultiPop;
import com.hxkcloud.patient.popup.NoticeTypeSelectPopWindow;
import com.hxkcloud.patient.request.MessageCode;
import com.hxkcloud.patient.request.YiJiaHuNetWorkUtils;
import com.hxkcloud.patient.utils.BrightnessUtils;
import com.hxkcloud.patient.utils.StringUtil;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * Created by william_sun on 2016-11-28.
 * Description:康复评价编辑新建页面
 */
public class BetterPlanEditActivity extends BaseActivity implements View.OnClickListener, NewDolistAdapter.NewDolistListener, CalendarMultiPop.onCalendarMultiPopFunc {

    //title
    private LinearLayout ll_title;
    private ImageView iv_back;
    private TextView tv_title;
    private TextView tv_send;

    private EditText et_name;
    private RecyclerView rv;

    private ArrayList<BetterPlanEditBean> doItems;
    private NewBetterPlanAdapter adapter;

    //两个按钮
    private PopupWindow popup_easynotice;
    private TextView tv_easynotice_title;
    private TextView tv_easynotice_cancel;
    private TextView tv_easynotice_func;
    //一个按钮
    private PopupWindow popup_easynotice1;
    private TextView tv_easynotice1_title;
    private TextView tv_easynotice1_func;
    //提醒类型选择
    private NoticeTypeSelectPopWindow typeWindow;
    //日期多选
    private CalendarMultiPop calendarMultiPop;

    private int funcType = 0;//列表监听操作内容，1删除整项提醒，2删除提醒下某个操作，3添加一个整提醒项，4发送确认，5返回确认
    private int noticePosition = 0;//操作整项提醒的位置
    private int noticeGroup = 0;//操作提醒下某个操作的提醒位置
    private int noticeChild = 0;//操作提醒下某个操作的操作位置

    private String orderId = "";//编辑的ID
//    private BetterPlanEditDetailBean detailBean;//编辑的单子

    private List<MonitorKindBean> monitors;//监测列表.

    private String patientId = "";//有的话给这一个使用，否则去选择患者助手
    private boolean isModify = false;//有patientId的时候，判断是修改还是新建

    private static List<MonitorKindBean> kinds;

    private boolean isBack = false;//添加护理措施的时候用到的
    private boolean isAutoCreate = false;//添加护理措施的时候用到的，自动生成有orderId，确是生成新的

    @Override
    protected void updateByHandler(Message msg) {
        switch (msg.what) {
            case MessageCode.NETWORKCODE_MONITORKIND_SUCCESS:
                kinds = (List<MonitorKindBean>) msg.obj;
                if (kinds != null && kinds.size() > 0) {
//                    MonitorKindDao monitorKindDao = new MonitorKindDao(mContext);
//                    monitorKindDao.setKind(kinds, "1");
                    typeWindow.initDatas(kinds);
                }
                typeWindow.show(ll_title);
                break;
            case MessageCode.PREGNANTBMIADD_BETTERPLANCREATE_SUCCESS:
                if ((msg.obj != null) && (!TextUtils.isEmpty((String) msg.obj))) {
                    toastMsg((String) msg.obj);
                } else {
                    toastMsg(R.string.datacommitsuccess);
                }

                if (isBack) {
                    Intent iBack = new Intent();
                    iBack.putExtra("back", isBack);
                    setResult(RESULT_OK, iBack);
                }
                finish();
                break;
            case MessageCode.PREGNANTBMIADD_BETTERPLANCREATE_FAILURE:
                if ((msg.obj != null) && (!TextUtils.isEmpty((String) msg.obj))) {
                    toastMsg((String) msg.obj);
                } else {
                    toastMsg(R.string.datacommitfail);
                }
                break;
            case MessageCode.PREGNANTBMIADD_BETTERPLANDETAIL_SUCCESS:
                BetterPlanEditDetailBean detailBean = (BetterPlanEditDetailBean) msg.obj;
                if (!TextUtils.isEmpty(detailBean.getListName())) {
                    et_name.setText(detailBean.getListName());
                }
                if (detailBean.getChildrenList() != null && detailBean.getChildrenList().size() > 0) {
                    for (BetterPlanEditDetailBean.BetterPlanEditBean1 editBean1 : detailBean.getChildrenList()) {
//                        doItems.add(editBean);
                        BetterPlanEditBean editBean = new BetterPlanEditBean();
//                        editBean.setRemindList(editBean1.getRemindList());
                        List<DolistEditFuncBean.funcBean> funcs = new ArrayList<>();
                        for (BetterPlanEditDetailBean.BetterPlanfuncBean1 func1 : editBean1.getRemindList()) {
                            DolistEditFuncBean.funcBean func = new DolistEditFuncBean.funcBean();
                            func.setContent(func1.getContent());
                            func.setRemindId(func1.getItemId());
                            func.setType(func1.getType());
                            funcs.add(func);
                        }
                        List<String> times = new ArrayList<>();
                        for (BetterPlanEditDetailBean.BetterPlanTimeBean1 time : editBean1.getTime()) {
                            times.add(time.getTime());
                        }
                        List<String> dates = new ArrayList<>();
                        for (BetterPlanEditDetailBean.BetterPlanDateBean1 date : editBean1.getDate()) {
                            dates.add(date.getDate());
                        }
                        editBean.setRemindList(funcs);
                        editBean.setDate(dates);
                        editBean.setTime(times);
                        doItems.add(editBean);
                    }
                    adapter.setData(doItems);
                    rv.setVisibility(View.VISIBLE);
                }
                break;
            case MessageCode.PREGNANTBMIADD_BETTERPLANDETAIL_FAILURE:
                if ((msg.obj != null) && (!TextUtils.isEmpty((String) msg.obj))) {
                    toastMsg((String) msg.obj);
                } else {
                    toastMsg(R.string.datagetfail);
                }
                finish();
                break;
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_newdolist);

        patientId = this.getIntent().getStringExtra("patientId");
        orderId = getIntent().getStringExtra("orderId");
        isModify = getIntent().getBooleanExtra("isModify", false);
        isBack = this.getIntent().getBooleanExtra("back", false);
        isAutoCreate = this.getIntent().getBooleanExtra("isAutoCreate", false);

        initView();
        initPopup();

        if (!TextUtils.isEmpty(orderId)) {
            loading();//编辑，获取单子详情
            YiJiaHuNetWorkUtils.betterPlanDetail(orderId, handler);
        }
    }

    @Override
    protected void initView() {
        ll_title = (LinearLayout) findViewById(R.id.ll_title);
        iv_back = (ImageView) findViewById(R.id.iv_title_back);
        tv_title = (TextView) findViewById(R.id.tv_title_title);
        tv_send = (TextView) findViewById(R.id.tv_title_func);

        et_name = (EditText) findViewById(R.id.et_newdolist_name);
        rv = (RecyclerView) findViewById(R.id.rv_newdolist);

        setTitlePadding(ll_title);
        iv_back.setVisibility(View.VISIBLE);
        tv_title.setText(getResources().getText(R.string.betterplan));
        et_name.setHint(R.string.clickinputbetterplanname);
        tv_send.setVisibility(View.VISIBLE);
        tv_send.setText(getResources().getText(R.string.send));
        iv_back.setOnClickListener(this);
        tv_send.setOnClickListener(this);

        doItems = new ArrayList<>();
        if (TextUtils.isEmpty(orderId)) {
            rv.setVisibility(View.VISIBLE);

            BetterPlanEditBean bean = new BetterPlanEditBean();//默认先添加一个，不可删除
            ArrayList<String> times = new ArrayList<>();
            times.add("08:00");
            bean.setTime(times);
//        bean.setArticleIds(new ArrayList<DolistArticleBean>());
//        bean.setCheckIds(new ArrayList<NoticeFunctionBean>());
            bean.setRemindList(new ArrayList<DolistEditFuncBean.funcBean>());
            SimpleDateFormat sdfDay = new SimpleDateFormat("yyyy-MM-dd");
            String curDay = sdfDay.format(new Date());
            ArrayList<String> dates = new ArrayList<>();
            dates.add(curDay);
            bean.setDate(dates);
            doItems.add(bean);
        } else {
            rv.setVisibility(View.GONE);
        }

        LinearLayoutManager mLayoutManager = new LinearLayoutManager(mContext);
        mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        rv.setLayoutManager(mLayoutManager);
        adapter = new NewBetterPlanAdapter(mContext, doItems, screenWidth, this);
        rv.setAdapter(adapter);

        MonitorKindDao monitorKindDao = new MonitorKindDao(mContext);
        monitors = monitorKindDao.getKinds();
    }

    private void initPopup() {
        //easynotice
        popup_easynotice = new PopupWindow(this);
        View viewNotice = LayoutInflater.from(this).inflate(R.layout.popup_easynotice, null);
        popup_easynotice.setContentView(viewNotice);

        popup_easynotice.setWidth((int) (screenWidth * 0.7));
        popup_easynotice.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        popup_easynotice.setFocusable(true);
        popup_easynotice.setTouchable(true);
        popup_easynotice.setOutsideTouchable(true);
        popup_easynotice.setBackgroundDrawable(new ColorDrawable(0x00000000));
        popup_easynotice.setAnimationStyle(R.style.popupwindow_anim_alpha);

        tv_easynotice_title = (TextView) viewNotice.findViewById(R.id.tv_easynotice_title);
        tv_easynotice_cancel = (TextView) viewNotice.findViewById(R.id.tv_easynotice_cancel);
        tv_easynotice_func = (TextView) viewNotice.findViewById(R.id.tv_easynotice_func);

        tv_easynotice_cancel.setOnClickListener(this);
        tv_easynotice_func.setOnClickListener(this);

        popup_easynotice.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                BrightnessUtils.lightOn(BetterPlanEditActivity.this);
                funcType = 0;
            }
        });

        //easynotice1
        popup_easynotice1 = new PopupWindow(this);
        View viewNotice1 = LayoutInflater.from(this).inflate(R.layout.popup_easynotice1, null);
        popup_easynotice1.setContentView(viewNotice1);

        popup_easynotice1.setWidth((int) (screenWidth * 0.7));
        popup_easynotice1.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        popup_easynotice1.setFocusable(true);
        popup_easynotice1.setTouchable(true);
        popup_easynotice1.setOutsideTouchable(true);
        popup_easynotice1.setBackgroundDrawable(new ColorDrawable(0x00000000));
        popup_easynotice1.setAnimationStyle(R.style.popupwindow_anim_alpha);

        tv_easynotice1_title = (TextView) viewNotice1.findViewById(R.id.tv_easynotice1_title);
        tv_easynotice1_func = (TextView) viewNotice1.findViewById(R.id.tv_easynotice1_func);

        tv_easynotice1_func.setOnClickListener(this);

        popup_easynotice1.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                BrightnessUtils.lightOn(BetterPlanEditActivity.this);
                funcType = 0;
            }
        });

//提醒类型选择
        typeWindow = new NoticeTypeSelectPopWindow(BetterPlanEditActivity.this);
        typeWindow.setNoticeTypeListener(new NoticeTypeSelectPopWindow.NoticeTypeListener() {
            @Override
            public void setNoticeType(String t) {
                int type = Integer.valueOf(t);
                typeWindow.dismiss();
//                DolistItemBean bean = doItems.get(noticePosition);

                if (type < monitors.size()) {
                    boolean exist = false;
                    for (int i = 0; i < doItems.get(noticePosition).getRemindList().size(); i++) {
                        if (doItems.get(noticePosition).getRemindList().get(i).getRemindId().equals(monitors.get(type).getKindId())) {
                            if (doItems.get(noticePosition).getRemindList().get(i).getType().equals("0")) {
                                exist = true;
                                break;
                            }
                        }
                    }

                    if (exist) {
                        toastMsg(R.string.hasmonitorremind);
                    } else {
                        DolistEditFuncBean.funcBean function = new DolistEditFuncBean.funcBean();
                        function.setContent(monitors.get(type).getName());
                        function.setRemindId(monitors.get(type).getKindId());
                        function.setType(YjhApplication.doorder_type_check);

                        doItems.get(noticePosition).getRemindList().add(function);
                        adapter.setData(doItems);
                    }
                } else if (type == monitors.size()) {//content
                    if (doItems.get(noticePosition).isHasContents()) {
                        toastMsg(R.string.hasremindword);
                    } else {
                        doItems.get(noticePosition).setHasContents(true);
                        DolistEditFuncBean.funcBean function = new DolistEditFuncBean.funcBean();
                        function.setContent("");
                        function.setRemindId("");
                        function.setType(YjhApplication.doorder_type_content);

                        doItems.get(noticePosition).getRemindList().add(function);
                        adapter.setData(doItems);
                    }
                } else {//article
                    //单选文章

                    Intent iCourse = new Intent(mContext, AddArticalActivity.class);
                    startActivityForResult(iCourse, 123);
                }

            }
        });

//日期多选
        calendarMultiPop = new CalendarMultiPop(BetterPlanEditActivity.this, this);
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {

    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            tv_easynotice_title.setText(getResources().getString(R.string.remindhavenotsendisreturn));
            tv_easynotice_cancel.setText(getResources().getString(R.string.cancel));
            tv_easynotice_func.setText(getResources().getString(R.string.returnback));
            funcType = 5;
            showNoticePopup(2);
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_title_back:
                tv_easynotice_title.setText(getResources().getString(R.string.remindhavenotsendisreturn));
                tv_easynotice_cancel.setText(getResources().getString(R.string.cancel));
                tv_easynotice_func.setText(getResources().getString(R.string.returnback));
                funcType = 5;
                showNoticePopup(2);
                break;
            case R.id.tv_title_func:
                String title = et_name.getText().toString().trim();
                if (StringUtil.isEmpty(title)) {
                    toastMsg(R.string.titleandremindisnull);
                    return;
                }
                for (BetterPlanEditBean item : doItems) {
                    if (item.getDate() == null || item.getDate().size() == 0) {
                        Toast.makeText(mContext, R.string.titleandremindisnull, Toast.LENGTH_LONG).show();
                        return;
                    }
                    if (item.getTime() == null || item.getTime().size() == 0) {
                        Toast.makeText(mContext, R.string.titleandremindisnull, Toast.LENGTH_LONG).show();
                        return;
                    }
                    if (item.getRemindList() == null || item.getRemindList().size() == 0) {
                        Toast.makeText(mContext, R.string.titleandremindisnull, Toast.LENGTH_LONG).show();
                        return;
                    }
                }

                if (TextUtils.isEmpty(orderId) || isAutoCreate) {
                    tv_easynotice_title.setText(getResources().getString(R.string.remindisreadyissend));
                } else {
                    tv_easynotice_title.setText(getResources().getString(R.string.remindismodifyissend));
                }
                tv_easynotice_cancel.setText(getResources().getString(R.string.cancel));
                tv_easynotice_func.setText(getResources().getString(R.string.send));
                funcType = 4;
                showNoticePopup(2);


                break;
            case R.id.tv_easynotice_cancel:
                popup_easynotice.dismiss();
                break;
            case R.id.tv_easynotice_func:
                if (funcType == 1) {//删除整项提醒
                    doItems.remove(noticePosition);
                    adapter.setData(doItems);
                    popup_easynotice.dismiss();
                } else if (funcType == 3) {//添加一个整提醒项
                    BetterPlanEditBean newItem = new BetterPlanEditBean();
//                    newItem.setItemList(new ArrayList<NoticeFunctionBean>());
//                    newItem.setTimeIds(new ArrayList<DolistTimeBean>());
//                    newItem.setDay("1");
                    ArrayList<String> times = new ArrayList<>();
                    times.add("08:00");
                    newItem.setTime(times);
//        bean.setArticleIds(new ArrayList<DolistArticleBean>());
//        bean.setCheckIds(new ArrayList<NoticeFunctionBean>());
                    newItem.setRemindList(new ArrayList<DolistEditFuncBean.funcBean>());
                    SimpleDateFormat sdfDay = new SimpleDateFormat("yyyy-MM-dd");
                    String curDay = sdfDay.format(new Date());
                    ArrayList<String> dates = new ArrayList<>();
                    dates.add(curDay);
                    newItem.setDate(dates);

                    doItems.add(newItem);
                    adapter.setData(doItems);
                    popup_easynotice.dismiss();
                } else if (funcType == 2) {//删除提醒下某个操作
                    if (doItems.get(noticeGroup).getRemindList().get(noticeChild).getType().equals("2")) {
                        doItems.get(noticeGroup).setHasContents(false);
                    }
                    doItems.get(noticeGroup).getRemindList().remove(noticeChild);
                    adapter.setData(doItems);
                    popup_easynotice.dismiss();
                } else if (funcType == 4) {
                    if (!TextUtils.isEmpty(patientId)) {
                        List<String> patientIds = new ArrayList<>();
                        if (!isModify) {
                            patientIds.add(patientId);
                        }
                        loading();
                        YiJiaHuNetWorkUtils.betterPlanCreate(et_name.getText().toString().trim(), orderId, patientIds, doItems, handler);
                    } else {
                        //选择用户
                        Intent iPatient = new Intent(mContext, ChooseUserActivity.class);
                        startActivityForResult(iPatient, 222);
                    }
                    popup_easynotice.dismiss();
                } else if (funcType == 5) {
                    popup_easynotice.dismiss();
                    finish();
                }
                break;
        }
    }

    public void showNoticePopup(int type) {
        if (type == 1) {
            popup_easynotice1.showAtLocation(ll_title, Gravity.CENTER, 0, 0);
            BrightnessUtils.lightOff(this);
            closeInputMethodManager();
        } else if (type == 2) {
            popup_easynotice.showAtLocation(ll_title, Gravity.CENTER, 0, 0);
            BrightnessUtils.lightOff(this);
            closeInputMethodManager();
        }
    }

    // 点击左侧标志按钮，0无操作，最后一个添加，中间的删除
    @Override
    public void onSignClick(int position) {
        if (position == 0) {//nothing

        } else if (position < doItems.size()) {//删除整项提醒
//            DolistItemBean bean = doItems.get(position);

            tv_easynotice_title.setText(getResources().getString(R.string.isdelthisnotice));
            tv_easynotice_cancel.setText(getResources().getString(R.string.cancel));
            tv_easynotice_func.setText(getResources().getString(R.string.delete));

            funcType = 1;
            noticePosition = position;
            showNoticePopup(2);

        } else {//添加整项提醒
            tv_easynotice_title.setText(getResources().getString(R.string.isaddnewnoticeitem));
            tv_easynotice_cancel.setText(getResources().getString(R.string.cancel));
            tv_easynotice_func.setText(getResources().getString(R.string.sure));

            funcType = 3;
            showNoticePopup(2);
        }
    }

    //点击任一项的添加提醒,选择血压提醒，血糖提醒，文字提醒，文章提醒
    @Override
    public void onAddnotice(int position) {
        closeInputMethodManager();
        noticePosition = position;

        if (!TextUtils.isEmpty(loginInfo.getDepartmentId())) {
            loading();
            YiJiaHuNetWorkUtils.getMonitorKind(loginInfo.getDepartmentId(), handler);
        }

    }

    //选择日期
    @Override
    public void addDayIndex(int position) {
        closeInputMethodManager();
        calendarMultiPop.showBottom(ll_title);
        List<Calendar> cs = new ArrayList<>();
        for (String csString : doItems.get(position).getDate()) {
            if (!TextUtils.isEmpty(csString) && csString.split("-").length > 2) {
                Calendar calendar = Calendar.getInstance();
                calendar.set(Integer.valueOf(csString.split("-")[0]), Integer.valueOf(csString.split("-")[1]) - 1, Integer.valueOf(csString.split("-")[2]));
                cs.add(calendar);
            }
        }
        calendarMultiPop.setCalendarss(cs);
        noticePosition = position;
//        List<Calendar> calendars = new ArrayList<>();
//        Calendar c1 = Calendar.getInstance();
//        c1.set(2016, 10, 25);
//        calendars.add(c1);
//        Calendar c2 = Calendar.getInstance();
//        c2.set(2016, 10, 26);
//        calendars.add(c2);
//        Calendar c3 = Calendar.getInstance();
//        c3.set(2016, 10, 27);
//        calendars.add(c3);
//        Calendar c4 = Calendar.getInstance();
//        c4.set(2016, 10, 24);
//        calendars.add(c4);
//        calendarMultiPop.setPoints(calendars);
    }

    //点击删除提醒项的操作
    @Override
    public void onDeleteFunction(int group, int child) {
        closeInputMethodManager();
        tv_easynotice_title.setText(getResources().getString(R.string.isdelthisnotice));
        tv_easynotice_cancel.setText(getResources().getString(R.string.cancel));
        tv_easynotice_func.setText(getResources().getString(R.string.delete));

        funcType = 2;
        noticeGroup = group;
//        noticeType = type;
        noticeChild = child;
        showNoticePopup(2);
    }

    //添加时间点
    @Override
    public void onAddTime(int position) {
        closeInputMethodManager();
        BetterPlanEditBean bean = doItems.get(position);
        Intent iTime = new Intent(this, NoticeTimeSelectActivity.class);
        iTime.putExtra("position", position);

        iTime.putExtra("type", "2");
        iTime.putStringArrayListExtra("times", (ArrayList<String>) bean.getTime());
        startActivityForResult(iTime, 0);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if (requestCode == 0) {
                int position = data.getIntExtra("position", 0);
                ArrayList<String> times = data.getStringArrayListExtra("times");
                doItems.get(position).setTime(times);
                adapter.setData(doItems);
            } else if (requestCode == 123) {
                //单选
//                String aId = data.getStringExtra("id");
//                String aName = data.getStringExtra("name");
//
//                boolean exist = false;
//                for (int i = 0; i < doItems.get(noticePosition).getItemList().size(); i++) {
//                    if (doItems.get(noticePosition).getItemList().get(i).getItemId().equals(aId)) {
//                        if (doItems.get(noticePosition).getItemList().get(i).getType().equals(YjhApplication.doorder_type_article)) {
//                            exist = true;
//                            break;
//                        }
//                    }
//                }
//
//                if (exist) {
//                    toastMsg(R.string.hascoursearticle);
//                } else {
//                    NoticeFunctionBean function = new NoticeFunctionBean();
//                    function.setContent(aName);
//                    function.setItemId(aId);
//                    function.setType(YjhApplication.doorder_type_article);
//
//                    doItems.get(noticePosition).getItemList().add(function);
//                    adapter.setData(doItems);

                //多选
                String[] ids = data.getStringArrayExtra("ids");
                String[] names = data.getStringArrayExtra("names");

                for (int j = 0; j < ids.length; j++) {
                    boolean exist = false;
                    for (int i = 0; i < doItems.get(noticePosition).getRemindList().size(); i++) {
                        if (doItems.get(noticePosition).getRemindList().get(i).getRemindId().equals(ids[j])) {
                            if (doItems.get(noticePosition).getRemindList().get(i).getType().equals(YjhApplication.doorder_type_article)) {
                                exist = true;
                            }
                        }
                    }
                    if (!exist) {
                        int articleCount = 0;
                        for (DolistEditFuncBean.funcBean func : doItems.get(noticePosition).getRemindList()) {
                            if (func.getType().equals(YjhApplication.doorder_type_article)) {
                                articleCount++;
                            }
                        }
                        if (articleCount >= 10) {
                            toastMsg(R.string.most10articles);
                            break;
                        } else {
                            DolistEditFuncBean.funcBean function = new DolistEditFuncBean.funcBean();
                            function.setContent(names[j]);
                            function.setRemindId(ids[j]);
                            function.setType(YjhApplication.doorder_type_article);

                            doItems.get(noticePosition).getRemindList().add(function);
                        }
                    }
                }
                adapter.setData(doItems);
            } else if (requestCode == 222) {//选择用户
                List<String> patients = data.getStringArrayListExtra("patients");
                loading();
                YiJiaHuNetWorkUtils.betterPlanCreate(et_name.getText().toString().trim(), orderId, patients, doItems, handler);
            }
        }
    }

    //多选日历操作确定
    @Override
    public void onCalendarMultiSure() {
        List<Calendar> cs = calendarMultiPop.getCalendarss();
        List<String> dates = new ArrayList<>();
        for (Calendar calendar : cs) {
            dates.add(calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-" + calendar.get(Calendar.DAY_OF_MONTH));
        }
//        toastMsg("cssize:" + cs.size());
        doItems.get(noticePosition).setDate(dates);
        adapter.setData(doItems);
        calendarMultiPop.dismiss();
    }

    //多选日历操作取消
    @Override
    public void onCalendarMultiCancel() {
        calendarMultiPop.dismiss();
    }

    //多选日历操作多余30提示
    @Override
    public void onCalendarMultimore30() {
        toastMsg(R.string.mostis30day);
    }
}
